package com.his.dictitem.controller;

import com.his.config.annotation.CurrentUser;
import com.his.dictitem.entity.DictItemCategory;
import com.his.dictitem.entity.DictItemCategoryKey;
import com.his.dictitem.service.DictItemCategoryService;
import com.his.dictitem.vo.DictItemCategoryVo;
import com.his.login.entity.DictEmployee;
import com.xiao.common.controller.ResultBaseController;
import com.xiao.common.util.BeanUtil;
import com.xiao.common.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目目录控制类
 * @Author tansonglin
 * @Date 2020/3/11
 */
@RestController
@RequestMapping(value="/api/dict_item_category")
public class DictItemCategoryController extends ResultBaseController {

    private  final Logger logger = (Logger) LoggerFactory.getLogger(this.getClass());

    @Autowired
    private DictItemCategoryService dictItemCategoryService;

    /**
     * 插入
     * @param dictItemCategoryVo
     * @return
     */
    @PostMapping(value="/insert.do")
    public ResultUtil insertDictItemCategory(@CurrentUser DictEmployee dictEmployee,@RequestBody DictItemCategoryVo dictItemCategoryVo){
        try {
            dictItemCategoryService.insert(dictEmployee,dictItemCategoryVo);
            return this.success("成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    /**
     * 根据主键删除目录
     * @param cateid 目录ID
     * @return
     */
    @GetMapping(value="/delete_bykey.do")
    public ResultUtil deleteDictItemCategoryByKey(@CurrentUser DictEmployee dictEmployee,String cateid){
        try {
            dictItemCategoryService.deleteByKey(dictEmployee,cateid);
            return this.success("成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    /**
     * 根据主键修改目录
     * @param dictItemCategoryVo
     * @return
     */
    @PostMapping(value="/update_by_selective.do")
    public ResultUtil updateDictItemCategory(@CurrentUser DictEmployee dictEmployee,@RequestBody DictItemCategoryVo dictItemCategoryVo){
        try {
            dictItemCategoryService.updateByKeySelective(dictEmployee,dictItemCategoryVo);
            return this.success("成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    /**
     * 根据过滤条件查询目录
     * @param dictItemCategoryVo
     * @return
     */
    @PostMapping(value="/query_by_selective.do")
    public ResultUtil queryDictItemCategoryBySelective(@CurrentUser DictEmployee dictEmployee,@RequestBody DictItemCategoryVo dictItemCategoryVo){
        try {
            List<DictItemCategory> dits=dictItemCategoryService.queryBySelective(dictEmployee,dictItemCategoryVo);
            return this.success("成功", dits);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
}
